package com.shawn.spring.boot.mybatisplus.mapper;

import com.shawn.spring.boot.mybatisplus.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.SelectKey;

/**
 * <p>
 * 系统用户 Mapper 接口
 * </p>
 *
 * @author shawn
 * @since 2020-08-30
 */
public interface UserMapper extends BaseMapper<User> {

  @Insert({
      "insert into t_user (username, password, ",
      "salt, email, mobile, ",
      "is_deleted, create_time, ",
      "update_time)",
      "values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
      "#{salt,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, ",
      "#{isDeleted,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, ",
      "#{updateTime,jdbcType=TIMESTAMP})"
  })
  @SelectKey(
      statement = "SELECT LAST_INSERT_ID()",
      keyProperty = "userId",
      before = false,
      resultType = Long.class)
  int insertReturnKey(User record);

}
